package com.umbacos.udm.client.view;

import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.umbacos.udm.client.arch.ImageButton;
import com.umbacos.udm.client.model.View;

public class TrackerListView extends View {

	public static final String CUR_TRK="There are currently X ctorrents and Y wgets active processes";
	
	public final VerticalPanel ftTrack = new VerticalPanel();

	public final ImageButton ibRefresh = new ImageButton("images/refresh2.png", 100, 24, 32);
	public final ImageButton ibNuke = new ImageButton("images/nuke.png", 100, 24, 32);
	public final ImageButton ibDown = new ImageButton("images/down.png", 100, 24, 32);
	public final ListBox lbFreq = new ListBox();

	public VerticalPanel getFtFiles() { return ftTrack; }

	public Label curTrk;

	public TrackerListView(){

		RootLayoutPanel rlp=RootLayoutPanel.get();

		ftTrack.setWidth(rlp.getOffsetWidth()-216 + "px");
		setContent(ftTrack);

		Grid hpTitle = new Grid(1,6);
		Image trackLogo = new Image("images/tracker.png");
		trackLogo.addStyleName("valignmiddle");
		
		Label trackTitle = new Label("Status Trackers");
		trackTitle.setStyleName("viewtitle");
		
		ibRefresh.setTitle("Refresh");
		ibNuke.setTitle("Kill all ctorrents, wgets and delete tracker files");
		ibDown.setTitle("Start a new wget download");

		HorizontalPanel toolBar=new HorizontalPanel();
		toolBar.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
		toolBar.setSpacing(5);
		toolBar.add(ibDown);
		toolBar.add(ibNuke);
		toolBar.add(ibRefresh);

		Image spacer=new Image("images/transparent.gif");
		spacer.setHeight("42px");
		
		lbFreq.addItem("Manual", "-1");
		lbFreq.addItem("1 sec", "1000");
		lbFreq.addItem("5 sec", "5000");
		lbFreq.addItem("10 sec", "10000");
		lbFreq.addItem("1 min", "60000");
		lbFreq.setSelectedIndex(0);
		lbFreq.setTitle("Refresh the list");
		
		curTrk = new Label(CUR_TRK.replaceAll("X", "0").replaceAll("Y", "0"));
		
		hpTitle.setWidth(rlp.getOffsetWidth()-200 + "px");
		hpTitle.getRowFormatter().setVerticalAlign(0, HasVerticalAlignment.ALIGN_MIDDLE);
		hpTitle.getCellFormatter().setHorizontalAlignment(0,3,HasHorizontalAlignment.ALIGN_CENTER);
		hpTitle.getCellFormatter().setHorizontalAlignment(0,4,HasHorizontalAlignment.ALIGN_RIGHT);
		hpTitle.getCellFormatter().setWidth(0, 0, "24px");
		hpTitle.getCellFormatter().setWidth(0, 1, "200px");
		hpTitle.getCellFormatter().setWidth(0, 3, "32px");
		hpTitle.getCellFormatter().setWidth(0, 4, "75px");
		hpTitle.getCellFormatter().setWidth(0, 5, "1px");

		hpTitle.setWidget(0, 0, trackLogo);
		hpTitle.setWidget(0, 1, trackTitle);
		hpTitle.setWidget(0, 2, curTrk);
		hpTitle.setWidget(0, 3, toolBar);
		hpTitle.setWidget(0, 4, lbFreq);
		hpTitle.setWidget(0, 5, spacer);

		setTitle(hpTitle);
	}
}
